<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>123</div>
    <script>
        class A {
            el = document.querySelector('div');
            clear () {
                this.el = null;
            }
            clearFromDOMTree () {
                document.body.removeChild(this.el);
                this.el = null;
            }
        }

        let el = document.querySelector('div');
        el = null;

        const ins1 = new A();
        const ins2 = new A();
        // ins2.clear();
        ins2.clearFromDOMTree();
        // 内存泄漏
        console.log(ins1, ins2);

        let obj = {
            el: document.querySelector('div'),
        };

        obj.el = null;
        obj = null;

    </script>
</body>
</html>